package com.samapp.indent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.samapp.MyApplication;
import com.samapp.R;

/**
 * 样品详情列表
 */
public class SampleDetailsActivity extends Activity implements OnClickListener {

	/** 返回按钮 */
	private Button btnBack = null;
	/** 添加样品详情按钮 */
	private Button btnAddSample = null;
	/** 上一步 */
	private Button btnFront = null;
	/** 下一步 */
	private Button btnNext = null;
	private ListView listViewSampleDetails = null;
	private SampleDetailAdapter mSampleDetailAdapter;
	private MyApplication myApplication = MyApplication.getApplicationInstance();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sample_details);
		init();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mSampleDetailAdapter.notifyDataSetChanged();
	}

	private void init() {
		initView();
		initListView();
		initListener();
	}

	private void initView() {
		btnBack = (Button) findViewById(R.id.btn_back);
		btnAddSample = (Button) findViewById(R.id.btn_add);
		btnFront = (Button) findViewById(R.id.btn_front);
		btnNext = (Button) findViewById(R.id.btn_next);
		listViewSampleDetails = (ListView) findViewById(R.id.listview_sample_details);
	}

	private void initListView() {
		mSampleDetailAdapter = new SampleDetailAdapter(SampleDetailsActivity.this, myApplication.newIndent.getSamples());
		listViewSampleDetails.setAdapter(mSampleDetailAdapter);
	}

	private void initListener() {
		btnBack.setOnClickListener(this);
		btnAddSample.setOnClickListener(this);
		btnFront.setOnClickListener(this);
		btnNext.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		case R.id.btn_add:
			skip(AddSampleDetailsActivity.class);
			break;
		case R.id.btn_front:
			finish();
			break;
		case R.id.btn_next:
			skip(IndentDetailsActivity.class);
			finish();
			break;
		}
	}

	/** 跳转页面 */
	private void skip(Class<?> cls) {
		Intent intent = new Intent(this, cls);
		startActivity(intent);
	}
}
